/**
 * Created by Administrator on 2016/1/6.
 */
var luid=localStorage.getItem("luid");
var ucoin=localStorage.getItem("ucoin");
var coin=0;
function OverScene(){
     this.$me=$("<div class='OverScene'></div>");
     var $top=$("<div class='top'></div>");
     var $second=$("<div class='second'></div>");
     var $three=$("<div class='three'></div>");
     var $mingci=$("<div class='mingci'>本局名次：<span>"+mc+"</span></div>");
	 var $next=$("<a href='#' class='next'></a>");
	 var $replay=$("<a href='#' class='replay'></a>");
     this.$me.append($top);
     this.$me.append($second);
     this.$me.append($three);
     this.$me.append($mingci);
     this.$me.append($next);
     this.$me.append($replay);
     var $wan=$("<button class='wan'></button>");
     this.$me.append($wan);
     var $wanq=$("<div class='wanq'></div>");
     this.$me.append($wanq);
     $next.click(function(){
     	director.runScene(new ScheduleScene());
     });
     $replay.click(function(){
     	director.runScene(new MineScene());
     });

    this.jiesuo=function(){
          if(mc==1){
              $wan.fadeIn(300 ,function(){
                   $wan.animate({top:"40%"});
                   $wanq.animate({top:"38%"});
               });
              $wan.html("恭喜过关<br>获得金币："+Number(playxinxi.guankaqian));
              //关闭
              $wanq.click(function(){
                  $wan.fadeOut(100);
                  $wanq.fadeOut(100);
              });
//******************更新用户数据库金币和关卡*******************************
            var jsonobj1={"handleid":11,"mission":Number(playxinxi.guankaid)+1,"userid":luid};
            //用AJAX发送
            $.ajax({
              type:"post",
              url:"handle/handout.php",
              dataType:"json",
              data:jsonobj1,
              success:function(data){
                //错误的情况
                //console.log(data);
                if(data['rs']=='error'){
                  console.log(data['rs']);
                }     
                //正确的情况
                if(data['rs']=='success'){
                  console.log("overcheck"+data['rs']);
//***********************************没有查到关卡再储存关卡*********************
                 var jsonobj2={"handleid":8,"mission":Number(playxinxi.guankaid)+1,"userid":luid,"coin":Number(ucoin)+Number(playxinxi.guankaqian)}; 
                 console.log(Number(ucoin)+Number(playxinxi.guankaqian));
                 console.log(luid);
                 //用AJAX发送
                  $.ajax({
                    type:"post",
                    url:"handle/handout.php",
                    dataType:"json",
                    data:jsonobj2,
                    success:function(data){
                      //错误的情况
                      if(data['rs']=='error'){
                    	console.log("over"+data['rs']);  
                        return ;
                      }     
                      //正确的情况
                      if(data['rs']=='success'){
                        console.log("over"+data['rs']);
                        }
                      },
                    error:function(responexml,name){
                    	alert("over"+name);
                     }
                     });
                }
                },
                error:function(responexml,name){
                  alert("overcheck"+name);
                 }
                });

 
          }
          else{
          	  $wan.fadeIn(300 ,function(){
                   $wan.animate({top:"40%"});
                   $wanq.animate({top:"38%"});
               });
              //关闭
              $wanq.click(function(){
                  $wan.fadeOut(100);
                  $wanq.fadeOut(100);
              });
              $wan.html("很遗憾没有过关，再来一次吧<br>获得金币："+Number(coin));
              //******************更新用户数据库金币*******************************
              var jsonobj3={"handleid":12,"userid":luid,"coin":Number(ucoin)+Number(coin)}; 
                       $.ajax({
                        type:"post",
                        url:"handle/handout.php",
                        dataType:"json",
                        data:jsonobj3,
                        success:function(data){
                          //错误的情况
                          if(data['rs']=='error'){
                        	console.log("coin"+data['rs']);
                            return ;
                          }     
                          //正确的情况
                          if(data['rs']=='success'){
                            
                            console.log("coin"+data['rs']);
                            }
                          },
                        error:function(responexml,name){
                          console.log("coin"+name);
                        }
                      }); 
          }
     }
    this.jiesuo();
}